/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sun.distributor.dao;

import com.sun.distributor.exceptions.InitException;
import com.sun.distributor.exceptions.QueryException;
import com.sun.distributor.exceptions.SystemException;
import com.sun.distributor.objects.Order;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Administrateur
 */
public class DAO_Order extends Abstract_DAO {

    public void insertOrder(Order ord) throws QueryException, SystemException, InitException {
        try {
            Connection c = getConnection();
            Statement stmt = c.createStatement();
            try {
                StringBuilder sqlString = new StringBuilder("insert into soa_order(OrderQuantity, Product_idProduct, Customer_idCustomer)");

                sqlString.append("values (").append(ord.getOrderQuantity()).append(", ");
                sqlString.append(ord.getProduct().getIdProduct()).append(",");
                sqlString.append(ord.getCustomer().getIdCustomer()).append(")");

                stmt.execute(sqlString.toString());

            } catch (SQLException ex) {
                throw new QueryException(ex);
            } finally {
                stmt.close();
                c.close();
            }
        } catch (SQLException ex) {
            throw new SystemException(ex);
        }
    }
}
